<?php

namespace Sharks\Core\Persistence\QueryBuilder;

use Sharks\Core\Exception\DatabaseException;
use Sharks\Core\Persistence\Db;
use Sharks\Core\Persistence\DbRecord;
use Sharks\Core\Persistence\Model;

/**
 * 查询通用方法
 */
abstract class AbstractSelectQuery extends AbstractQuery {

    /**
     * 组装对象
     * @param array $data
     * @return null|DbRecord
     */
    protected function buildObj(array $data) {
        if (empty($data)) {
            return null;
        }

        if (!is_null($this->class)) {
            return Model::generate($this->class->getName(), $data);
        }
        else {
            return DbRecord::convert($data);
        }
    }

    /**
     * 组装数组对象
     * @param array $datas
     * @return array
     */
    protected function buildObjs(array $datas) {
        $result = array();
        foreach ($datas as $data) {
            $result[] = $this->buildObj($data);
        }
        return $result;
    }


}